//
//  CommonDiseasesClickViewController.m
//  WE
//
//  Created by 要帅气的生活 on 15/12/3.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "CommonDiseasesClickViewController.h"
#import "Size.h"
#import "HeadView.h"
#import "ThreeCell.h"
#import "QuickaboutLongdistancetoseeadoctorTableViewCell.h"
#import "TwoCell.h"
#import "MoreTeamViewController.h"
#import "MoreRelatedAdviCell.h"
#import "SingletonStoreSimpleData.h"
#import "CommonDiseasesWebViewController.h"
#import "AdvisoryDetailsViewController.h"
#import "RelatedAdviViewController.h"
#import "MoreAdviViewController.h"
#import "DiseaseViewController.h"

@interface CommonDiseasesClickViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *table;
@property (nonatomic,strong) UIView *bottomView;
@end

@implementation CommonDiseasesClickViewController
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
    [SingletonStoreSimpleData shareViewController].array = nil;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = _str;
    [self addtableView];
    [self creatBottomBtn];
}

- (void)creatBottomBtn
{
    NSArray * arr = @[@"预约挂号",@"在线咨询"];
    NSArray * arr1 = @[@"iconfont-guahao",@"iconfont-zixun"];
    self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, WindowHeight - 49, WindowWidth, 49)];
    [ToolUtil createLine:0 superView:_bottomView lift:0 width:_bottomView.frame.size.width hight:1 color:GRAYCOLOR];
    
    [ToolUtil createVerticalLine:0 superView:_bottomView lift:WindowWidth / 2 - 1 height:_bottomView.frame.size.height];
    for (int i = 0; i < 2; i++) {
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(i *(WindowWidth / 2 ) ,1, (WindowWidth / 2 -1), 48);
        [btn addTarget:self action:@selector(clickbtn:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 300 + i;
        btn.backgroundColor = [UIColor whiteColor];
        
        UIImageView * aImageView = [[UIImageView alloc] initWithFrame:CGRectMake( ((WindowWidth / 2) - 94)/2, 15, 25, 25)];
        aImageView.layer.masksToBounds = YES;
        aImageView.layer.cornerRadius = 12.5;
        if (i == 0) {
            
            aImageView.backgroundColor = [UIColor colorWithRed:0.4159 green:0.5049 blue:1.0 alpha:1.0];
        }
        aImageView.image = [UIImage imageNamed:arr1[i]];
        UILabel * lbl = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(aImageView.frame) + margin_10, 15, margin_64, margin_20)];
        lbl.font = FONT(14);
        lbl.text = arr[i];
        [btn addSubview:lbl];
        [btn addSubview:aImageView];
        [self.bottomView addSubview:btn];
    }
    [self.view addSubview:self.bottomView];
}

- (void)clickbtn:(UIButton *)btn
{
    if (btn.tag == 300) {
        NSLog(@"挂号");
        MoreAdviViewController * moreAdviVC = [[MoreAdviViewController alloc] init];
        [self.navigationController pushViewController:moreAdviVC animated:YES];
    }else if (btn.tag == 301){
        MoreAdviViewController * moreAdviVC = [[MoreAdviViewController alloc] init];
        [self.navigationController pushViewController:moreAdviVC animated:YES];
        
        NSLog(@"咨询");
    }
    
}


-(void)addtableView{
    _table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, WindowHeight-49) style:UITableViewStyleGrouped];
    [self.view addSubview:_table];
    _table.delegate = self;
    _table.dataSource = self;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 2;
    }else if (section == 1){
        return 3;
    }else if (section == 2){
        return 1;
    }else{
        return 2;
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commone"];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"commone"];
            }
            cell.textLabel.text = @"说的我看见啦会计师的徕卡我哈就登记卡上啊厚度为哈卡还是看觉得好玩就看哈看机会时间肯撒网打我打的哇哇哇";
            cell.textLabel.numberOfLines = 0;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else{
            [SingletonStoreSimpleData shareViewController].array = @[[UIImage imageNamed:@"shouye3"],[UIImage imageNamed:@"shouye4"],[UIImage imageNamed:@"shouye5"]].mutableCopy;
            ThreeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commones"];
            if (cell == nil) {
                cell = [[ThreeCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"commones"];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
    }else if (indexPath.section == 1){
        NSArray *arr = @[@"您经常有反酸、烧心的症状嘛？",@"什么是胃食管反流病（GERD）？",@"胃食管反流病有哪些并发症？"];
        QuickaboutLongdistancetoseeadoctorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commtwo"];
        if (cell == nil) {
            cell = [[QuickaboutLongdistancetoseeadoctorTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"commtwo"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.label.text = arr[indexPath.row];
        return cell;
    }else if (indexPath.section == 2){
        TwoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commthree"];
        if (cell == nil) {
            cell = [[TwoCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"commthree"];
        }
        cell.nameleft.text = @"吴继敏";
        cell.nameright.text = @"袁耀宗";
        [cell.left addTarget:self selector:@selector(nemaleft)];
        [cell.right addTarget:self selector:@selector(nemaright)];
        cell.labelright.text = @"胃顽固性反流";
        cell.labelleft.text = @"功能性胃肠病";
        cell.widthr = [ToolUtil autoWidth:@"胃顽固性反流" width:0 height:20 num:12];
        cell.widthl = [ToolUtil autoWidth:@"功能性胃肠病" width:0 height:20 num:12];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        MoreRelatedAdviCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commfour"];
        if (cell == nil) {
            cell = [[MoreRelatedAdviCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"commfour"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 35;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 3) {
        return 0.1;
    }else{
        
        return 20;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (indexPath.row == 1) {
            return 110;
        }else{
            return 110;
        }
    }
    else if (indexPath.section == 1) {
        return 45;
    }
    else if (indexPath.section == 2) {
        return 90;
    }
    else if (indexPath.section == 3) {
        return 200;
    }else{
        return 0;
    }
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    NSArray *arr = @[_str,@"疾病常识",@"专家团队",@"相关资讯"];
    
    if (section == 2) {
        HeadView *head = [[HeadView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 35)];
        head.backgroundColor = [UIColor whiteColor];
        head.img.image = [UIImage imageNamed:@"duoren.png"];
        head.label.text = arr[section];
        head.beijin.backgroundColor = [UIColor colorWithRed:86.0f/255.0f green:138.0f/225.0f blue:255.0f/255.0f alpha:1];
        [head.right addTarget:self selector:@selector(zhuanjia)];
        return head;
    }else if (section == 0)
    {
        HeadView *three = [[HeadView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 35)];
        three.backgroundColor = [UIColor whiteColor];
        three.img.image = [UIImage imageNamed:@"iconfont-jia"];
        three.label.text = arr[section];
        three.beijin.backgroundColor = [UIColor colorWithRed:190.0f/255.0f green:33.0f/225.0f blue:3.0f/255.0f alpha:1];
        [three.right addTarget:self selector:@selector(commxianqing)];
        return three;
    }else if(section == 3)
    {
        HeadView *foun = [[HeadView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 35)];
        foun.backgroundColor = [UIColor whiteColor];
        foun.img.image = [UIImage imageNamed:@"remen.png"];
        foun.label.text = arr[section];
        foun.beijin.backgroundColor = [UIColor colorWithRed:241.0f/255.0f green:82.0f/225.0f blue:44.0f/255.0f alpha:1];
        [foun.right addTarget:self selector:@selector(commrelated)];
        return foun;
    }else{
        HeadView *foun = [[HeadView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 35)];
        foun.backgroundColor = [UIColor whiteColor];
        foun.img.image = [UIImage imageNamed:@"iconfont-shu"];
        foun.label.text = arr[section];
        foun.beijin.backgroundColor = [UIColor colorWithRed:253.0f/255.0f green:162.0f/225.0f blue:10.0f/255.0f alpha:1];
        [foun.right addTarget:self selector:@selector(commONE)];
        return foun;
    }
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 3) {
        AdvisoryDetailsViewController *advisory = [AdvisoryDetailsViewController new];
        advisory.view.backgroundColor = [UIColor whiteColor];
        [self.navigationController pushViewController:advisory animated:YES];
    }
}

-(void)commONE{
    NSLog(@"疾病更多");
    CommonDiseasesWebViewController *commweb = [CommonDiseasesWebViewController new];
    commweb.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController pushViewController:commweb animated:YES];
}
-(void)commxianqing{
    NSLog(@"详情更多");
    DiseaseViewController *dis = [[DiseaseViewController alloc] init];
    dis.string = _str;
    [self.navigationController pushViewController:dis animated:YES];
    
}
-(void)commrelated{
    NSLog(@"相关更多");
    RelatedAdviViewController *more = [RelatedAdviViewController new];
    more.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController pushViewController:more animated:YES];
}
-(void)zhuanjia{
    NSLog(@"专家");
    [self.navigationController pushViewController:[[MoreTeamViewController alloc] init] animated:YES];
}
-(void)nemaleft{
    NSLog(@"left");
    TeamViewController *team = [TeamViewController new];
    [self.navigationController pushViewController:team animated:YES];
    team.navigationController.navigationBar.hidden = NO;
}
-(void)nemaright{
    NSLog(@"right");
    TeamViewController *team = [TeamViewController new];
    [self.navigationController pushViewController:team animated:YES];
    team.navigationController.navigationBar.hidden = NO;
}
@end
